# Methods added to this helper will be available to all templates in the application.
module ApplicationHelper
  
  def log_tag
    if @activeuser.guest?
      link_to "登陆", :controller=>"login", :action => "index"
    else
      link_to "注销", :controller=>"login", :action => "logout"
    end
  end
  
  def head_tag
    if @activeuser.guest?
      "Your Salary Benchmark Online"
    else
      if @activeuser.adminstrative?
        "<span>" + link_to("管理站点信息和数据", :controller=>"admin") + "</span>&nbsp;<span>" + link_to("查看站点统计和信息", :controller=>"sitealizer") + "</span>"
      else 
        link_to "管理个人信息和资料", :controller=>"info"
      end
    end
  end
  
  def show_banner(user,company,incumbent)
    '来自 '+user.to_s+' 位会员的 '+company.to_s+' 家公司的 '+incumbent.to_s+' 个工资条...'  
  end
  
  def show_keyword(keywords)
    ret="热门搜索: "
    keywords.each do |k|
      ret=ret+ link_to(k.word, :controller=>"search", :action=>"search_keyword", :id=>k.id)
    end
    return ret
  end
  
  def show_evaluation(eva)
    image_tag("/evl/r"+eva.evaluate_red+".gif",:alt=>"统计可信度") + "</br>" + image_tag("/evl/g"+eva.evaluate_green+".gif",:alt=>"评估可信度")
  end
  
  def show_picture(object)
    category=Category.find_category(object)
    '<div style="width:62px;height:62px;"><div class="out"><div class="in"><img id="image_'+category.id.to_s+'_'+object.id.to_s+'" src=' + url_for(:controller=>"index",:action=>"post_picture",:id=> object.picture_id)+ ' width="60*60"/></div></div></div>'
  end
  
  def show_report_picture(report)
    if report.class.name=="CompanyReport"
      id=report.company.picture_id
      if id==2
        '<div style="width:62px;height:62px;"><div class="out"><div class="in"><img src="/images/company.gif" width="60*60"/></div></div></div>'
      else
        '<div style="width:62px;height:62px;"><div class="out"><div class="in"><img src=' + url_for(:controller=>"index",:action=>"post_picture",:id=>id )+ ' width="60*60"/></div></div></div>' 
      end      
    elsif report.class.name=="CityReport"
      '<div style="width:62px;height:62px;"><div class="out"><div class="in"><img src="/images/city.gif" width="60*60"/></div></div></div>' 
    elsif report.class.name=="PositionReport"
      '<div style="width:62px;height:62px;"><div class="out"><div class="in"><img src="/images/position.gif" width="60*60"/></div></div></div>'
    else
      id=report.User.picture_id
      if id==1
        '<div style="width:62px;height:62px;"><div class="out"><div class="in"><img src="/images/user.gif" width="60*60"/></div></div></div>'
      else
        '<div style="width:62px;height:62px;"><div class="out"><div class="in"><img src=' + url_for(:controller=>"index",:action=>"postpicture",:id=> id)+ ' width="60*60"/></div></div></div>'
      end
    end 
  end
  
  def show_tag_list(tag_list,category,length=0)
      ret=""
      length=0 if tag_list.length<length
      tag_list[0..length-1].each do |tag|
        ret=ret+link_to(tag.word, :controller=>"search", :action=>"search_tagword", :id=>tag.id, :category=>category)+" "
      end
      return ret
  end
  
  def show_user_status(user)
    if user.banned?
      image_tag("lock.gif", :class => "icon orange", :title => "封禁中...")
    else
      user.anonymous ? image_tag("smile.gif", :class => "icon grey", :title => "匿名中...") : image_tag("smile.gif", :class => "icon orange", :title => "活跃中...")
    end
  end
  
  def highlight_keyword(string,query_arrays=[])
    return string if query_arrays[0]=="" || query_arrays==[]
    temp='('
    query_arrays.each {|highstring| temp=temp<<highstring+'|'}
    temp = temp[0..-2]
    temp = temp<<')'
    temp = Regexp.new(temp)
    string=string.gsub(temp, '<span class="highlight">\1</span>')
    return string
  end
  
  def list_notice(flash)
    if flash
      ret="<ul>"
      flash[0...3].each do |notice|
        ret=ret+"<li>"+notice+"</li>"
      end
      ret=ret+"</ul>"
    end
    return ret
  end
  
  def show_user_tag(user)
    if user && user.anonymous==false
      link_to h(user.name), :controller=>"view", :action=>"read_user", :id=>user.id
    elsif user
      link_to "匿名用户", :controller=>"view", :action=>"read_user", :id=>user.id
    else
      "匿名用户"
    end
   end
   
   def audit_company(company)
    unless @activeuser.own(company)
      link_to "我来挑错", {}
    end
  end
  
end
